﻿using System;
using System.Reflection;
using System.Threading;
using HslCommunication.Reflection;
using Newtonsoft.Json;

namespace HslCommunication.MQTT
{
	/// <summary>
	/// Mqtt的同步网络服务的单Api信息描述类<br />
	/// Single Api information description class of Mqtt's synchronous network service
	/// </summary>
	// Token: 0x020000CB RID: 203
	public class MqttRpcApiInfo
	{
		/// <summary>
		/// 当前的Api的路由信息，对于注册服务来说，是类名/方法名
		/// </summary>
		// Token: 0x17000236 RID: 566
		// (get) Token: 0x06000F38 RID: 3896 RVA: 0x00059B82 File Offset: 0x00057D82
		// (set) Token: 0x06000F39 RID: 3897 RVA: 0x00059B8A File Offset: 0x00057D8A
		public string ApiTopic { get; set; }

		/// <summary>
		/// 当前的Api的路由说明
		/// </summary>
		// Token: 0x17000237 RID: 567
		// (get) Token: 0x06000F3A RID: 3898 RVA: 0x00059B93 File Offset: 0x00057D93
		// (set) Token: 0x06000F3B RID: 3899 RVA: 0x00059B9B File Offset: 0x00057D9B
		public string Description { get; set; }

		/// <summary>
		/// 当前Api的调用次数
		/// </summary>
		// Token: 0x17000238 RID: 568
		// (get) Token: 0x06000F3C RID: 3900 RVA: 0x00059BA4 File Offset: 0x00057DA4
		// (set) Token: 0x06000F3D RID: 3901 RVA: 0x00059BAC File Offset: 0x00057DAC
		public long CalledCount
		{
			get
			{
				return this.calledCount;
			}
			set
			{
				this.calledCount = value;
			}
		}

		/// <summary>
		/// 示例的
		/// </summary>
		// Token: 0x17000239 RID: 569
		// (get) Token: 0x06000F3E RID: 3902 RVA: 0x00059BB5 File Offset: 0x00057DB5
		// (set) Token: 0x06000F3F RID: 3903 RVA: 0x00059BBD File Offset: 0x00057DBD
		public string ExamplePayload { get; set; }

		/// <summary>
		/// 当前Api的调用总耗时，单位是秒
		/// </summary>
		// Token: 0x1700023A RID: 570
		// (get) Token: 0x06000F40 RID: 3904 RVA: 0x00059BC6 File Offset: 0x00057DC6
		// (set) Token: 0x06000F41 RID: 3905 RVA: 0x00059BD9 File Offset: 0x00057DD9
		public double SpendTotalTime
		{
			get
			{
				return (double)this.spendTotalTime / 100000.0;
			}
			set
			{
				this.spendTotalTime = (long)(value * 100000.0);
			}
		}

		/// <summary>
		/// 当前Api是否为方法，如果是方法，就为true，否则为false
		/// </summary>
		// Token: 0x1700023B RID: 571
		// (get) Token: 0x06000F42 RID: 3906 RVA: 0x00059BED File Offset: 0x00057DED
		// (set) Token: 0x06000F43 RID: 3907 RVA: 0x00059BF5 File Offset: 0x00057DF5
		public bool IsMethodApi { get; set; }

		/// <summary>
		/// 如果当前的API接口是支持Http的请求方式，当前属性有效，例如GET,POST
		/// </summary>
		// Token: 0x1700023C RID: 572
		// (get) Token: 0x06000F44 RID: 3908 RVA: 0x00059BFE File Offset: 0x00057DFE
		// (set) Token: 0x06000F45 RID: 3909 RVA: 0x00059C06 File Offset: 0x00057E06
		public string HttpMethod { get; set; } = "GET";

		/// <summary>
		/// 当前的Api的方法是否是异步的Task类型
		/// </summary>
		// Token: 0x1700023D RID: 573
		// (get) Token: 0x06000F46 RID: 3910 RVA: 0x00059C0F File Offset: 0x00057E0F
		// (set) Token: 0x06000F47 RID: 3911 RVA: 0x00059C17 File Offset: 0x00057E17
		[JsonIgnore]
		public bool IsOperateResultApi { get; set; }

		/// <summary>
		/// 当前的Api关联的方法反射，本属性在JSON中将会忽略
		/// </summary>
		// Token: 0x1700023E RID: 574
		// (get) Token: 0x06000F48 RID: 3912 RVA: 0x00059C20 File Offset: 0x00057E20
		// (set) Token: 0x06000F49 RID: 3913 RVA: 0x00059C28 File Offset: 0x00057E28
		[JsonIgnore]
		public MethodInfo Method
		{
			get
			{
				return this.method;
			}
			set
			{
				this.method = value;
				this.IsMethodApi = true;
			}
		}

		/// <summary>
		/// 当前的Api关联的方法反射，本属性在JSON中将会忽略
		/// </summary>
		// Token: 0x1700023F RID: 575
		// (get) Token: 0x06000F4A RID: 3914 RVA: 0x00059C3A File Offset: 0x00057E3A
		// (set) Token: 0x06000F4B RID: 3915 RVA: 0x00059C42 File Offset: 0x00057E42
		[JsonIgnore]
		public PropertyInfo Property
		{
			get
			{
				return this.property;
			}
			set
			{
				this.property = value;
				this.IsMethodApi = false;
			}
		}

		/// <summary>
		/// 当前Api的方法的权限访问反射，本属性在JSON中将会忽略
		/// </summary>
		// Token: 0x17000240 RID: 576
		// (get) Token: 0x06000F4C RID: 3916 RVA: 0x00059C54 File Offset: 0x00057E54
		// (set) Token: 0x06000F4D RID: 3917 RVA: 0x00059C5C File Offset: 0x00057E5C
		[JsonIgnore]
		public HslMqttPermissionAttribute PermissionAttribute { get; set; }

		/// <summary>
		/// 当前Api绑定的对象的，实际的接口请求，将会从对象进行调用，本属性在JSON中将会忽略
		/// </summary>
		// Token: 0x17000241 RID: 577
		// (get) Token: 0x06000F4E RID: 3918 RVA: 0x00059C65 File Offset: 0x00057E65
		// (set) Token: 0x06000F4F RID: 3919 RVA: 0x00059C6D File Offset: 0x00057E6D
		[JsonIgnore]
		public object SourceObject { get; set; }

		/// <summary>
		/// 使用原子的操作增加一次调用次数的数据信息，需要传入当前的消耗的时间，单位为100倍毫秒
		/// </summary>
		/// <param name="timeSpend">当前调用花费的时间，单位为100倍毫秒</param>
		// Token: 0x06000F50 RID: 3920 RVA: 0x00059C76 File Offset: 0x00057E76
		public void CalledCountAddOne(long timeSpend)
		{
			Interlocked.Increment(ref this.calledCount);
			Interlocked.Add(ref this.spendTotalTime, timeSpend);
		}

		/// <inheritdoc />
		// Token: 0x06000F51 RID: 3921 RVA: 0x00059C92 File Offset: 0x00057E92
		public override string ToString()
		{
			return this.ApiTopic;
		}

		// Token: 0x04000422 RID: 1058
		private long calledCount = 0L;

		// Token: 0x04000423 RID: 1059
		private long spendTotalTime = 0L;

		// Token: 0x04000424 RID: 1060
		private MethodInfo method;

		// Token: 0x04000425 RID: 1061
		private PropertyInfo property;
	}
}
